package gx.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import gx.service.ProductService;

@Controller
@RequestMapping("/mng/pcount")
public class PcountController {
@Autowired
private ProductService productService;

@RequestMapping("/out.jhtml")
public ModelAndView purc(){
	ModelAndView mav=new ModelAndView("/mng/pount/out");
	int year=2017;
	Map<String,Long> map=productService.totalInventory(year);
	StringBuffer m=new StringBuffer();
	StringBuffer data=new StringBuffer();
	int i = 0;
	for (Map.Entry<String, Long> maps : map.entrySet()) {
		if (i++ > 0) {
			m.append(",");
			data.append(",");
		}
		m.append("'");
		m.append(maps.getKey());
		m.append("'");
		data.append(maps.getValue().longValue());
	}

	mav.addObject("year", year);
	mav.addObject("months", m.toString());
	mav.addObject("datas", data.toString());

	// 库存按分类比例

	Map<String, Long> map_c = productService
			.totalInventoryByCategory(year);
	int j = 0;
	StringBuffer datas2 = new StringBuffer();
	for (Map.Entry<String, Long> mentry : map_c.entrySet()) {
		if (j++ > 0) {
			datas2.append(",");
		}
		datas2.append("['" + mentry.getKey() + "'," + mentry.getValue()
				+ "]");
	}

	mav.addObject("datas2", datas2.toString());

return mav;
 }
}
